//
// Created on 2025/8/13.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#include "RNCNativeEngineViewComponentInstance.h"

namespace rnoh {
RNCNativeEngineViewComponentInstance::RNCNativeEngineViewComponentInstance(Context context)
    : CppComponentInstance(std::move(context)) {}

RNCNativeEngineViewComponentInstance::~RNCNativeEngineViewComponentInstance() {}

void RNCNativeEngineViewComponentInstance::onChildInserted(ComponentInstance::Shared const &childComponentInstance,
                                                           std::size_t index) {
    CppComponentInstance::onChildInserted(childComponentInstance, index);
    auto mWidth = childComponentInstance->getLayoutMetrics().frame.size.width;
}

void RNCNativeEngineViewComponentInstance::onChildRemoved(ComponentInstance::Shared const &childComponentInstance) {
    CppComponentInstance::onChildRemoved(childComponentInstance);
};

RNCEngineNode &RNCNativeEngineViewComponentInstance::getLocalRootArkUINode() { return m_EngineNode; }

void RNCNativeEngineViewComponentInstance::onPropsChanged(SharedConcreteProps const &props) {
    CppComponentInstance::onPropsChanged(props);
    if (props == nullptr) {
        return;
    }
    DLOG(INFO) << "sssss-------->onPropsChanged antiAliasing:" << props->antiAliasing;
    DLOG(INFO) << "sssss-------->onPropsChanged isTransparent:" << props->isTransparent;
    DLOG(INFO) << "sssss-------->onPropsChanged androidView:" << props->androidView;
    if (props->antiAliasing) {
        m_EngineNode.setAntiAliasing(props->antiAliasing);
    }
    if (props->isTransparent) {
        m_EngineNode.setIsTransparent(props->isTransparent);
    }
    m_EngineNode.setAndroidView(props->androidView);
}

void RNCNativeEngineViewComponentInstance::onSnapshotDataReturned(std::string data) {
    if (m_eventEmitter) {
        m_eventEmitter->onSnapshotDataReturned({data});
    }
};

void RNCNativeEngineViewComponentInstance::handleCommand(std::string const &commandName, folly::dynamic const &args) {
     DLOG(INFO) << "sssss-------->handleCommand:" << commandName;
    if (commandName == "takeSnapshot") {
    
    }
};

}; // namespace rnoh
